<%
	def tokenUrl = grailsApplication.config.app.domain.url + createLink(controller: 'eventAlbumToken', action: 'processToken', params: [tokenId : token])
%>

<div class="separatorUsingBorder"></div>

<h2>
	<g:message code="share.albumsPassword" />
</h2>

<div class="alert alert-success">
	<a class="close" data-dismiss="alert">×</a>
	<div class="message">
		<g:message code="share.generate.key.success" />
	</div>
</div>

<div id="currentEventTokenMessages"></div>

<div class="titleDescription">
	<p><g:message code="share.ways" /></p>
</div>

<div class="form-horizontal">

	<div class="control-group">
		<label class="control-label" for="token"><g:message
				code="share.albumsPassword" /></label>
		<div class="controls">
			<g:field id="inputTokenField" class="totalWidth" type="text"
				name="tokenField" value="${token}"
				placeholder="${message(code: 'share.albumsPassword')}" />
		</div>
	</div>

	<div class="control-group">
		<label class="control-label" for="tokenUrl"><g:message
				code="share.url" /></label>
		<div class="controls">
			<g:field id="inputTokenUrlField" class="totalWidth" type="text"
				name="tokenUrl" value="${tokenUrl}" />
		</div>
	</div>
	
	<div class="control-group">
		<label class="control-label" for="tokenUrl"><g:message
				code="qrcode" /></label>
		<div class="controls">
			<qrcode:image text="${token}" height="200" width="200"/>
		</div>
	</div>
		
</div>

<g:form id="sendEmailTokenInfo" name="sendEmailTokenInfo"
			controller="eventAlbumToken" action="sendEmail">
	<g:hiddenField name="tokenUrl" value="${tokenUrl}" />
	<g:hiddenField name="token" value="${token}" />
</g:form>
			
<div class="btn-group">
	<button id="sendEmail" class="btn btn-success">
		<g:message code="share.send.email" />
	</button>
</div>
									
<script type="text/javascript">

	$(document).ready(function() {
	
		/*
		 * Generate token submit form
		 */
		 $("#sendEmail").click(function() {
		 	$('#loadingPopup').modal('show')
		 	onEmailSend();
		});			
  	});

   	function onEmailSend() {
	   	jQuery.ajax({
	                 type: 'POST',
	                 data: $('#sendEmailTokenInfo').serialize(),        
	                 url: "${createLink(controller: 'eventAlbumToken', action: 'sendEmail')}",
	                 async:true,
	                 datatype:"json",
	                 success: function(data,textStatus) { 
	                 		          
						      var position = undefined;
						      		                 		                       		  	
	                          if(data.error){
	                          	$("#currentEventTokenMessages").html("<div class='alert alert-error'><a class='close' data-dismiss='alert'>×</a><div class='message'>" + data.message + "</div></div>");
	                          } 
	                          else{
	                          	 $("#currentEventTokenMessages").html("<div class='alert alert-success'><a class='close' data-dismiss='alert'>×</a><div class='message'>" + data.message + "</div></div>");
	                          }
	                          
	                         $('#loadingPopup').modal('hide')
	                          
	                          var $target = $('html,body'); 
							  $target.animate({scrollTop: $target.height()}, 1000);
	                 }
	  			});
	  }	

</script>

<div class="separator"></div>